package com.alipaydemo.pay.controller;

import com.alipay.api.AlipayApiException;
import com.alipaydemo.pay.pojo.OrderVo;
import com.alipaydemo.pay.PayUtils;
import com.alipaydemo.pay.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @date 2023/2/18
 */
@RestController
@RequestMapping("pay")
public class PayController {

    @Autowired
    private PayUtils payUtils;

    /**
     * 创建订单
     * @param ordersVo
     * @return
     */
    @RequestMapping(value = "createOrder",method = RequestMethod.POST)
    public Result createOrder(@RequestBody OrderVo ordersVo){
        ordersVo.setOrderNo("ONO"+ UUID.randomUUID().toString().replaceAll("-",""));//生成订单号（自定义）
       return payUtils.createOrder(ordersVo);
    }

    /**
     * 查询订单状态
     * @param outTradeNo
     * @return
     */
    @RequestMapping(value = "queryOutTradeNo",method = RequestMethod.GET)
    public Result returnApi (String outTradeNo) throws AlipayApiException {
        return payUtils.queryOrderFromAli(outTradeNo);
    }

}
